package com.example.exercise.MysqlUtil;

import java.sql.Connection;

import java.sql.DriverManager;



public class DBHelper {



    private static final String driver = "com.mysql.cj.jdbc.Driver"; // 数据库驱动

    private static final String url = "jdbc:mysql://47.111.53.113:3306/exercise?useUnicode=true&characterEncoding=UTF-8";

    private static final String username = "huangsikai";// 数据库的用户名

    private static final String password = "Shsmyxx12310";// 数据库的密码

    private static Connection conn = null;


    static {

        try {

            Class.forName(driver);

        } catch (Exception ex) {

            ex.printStackTrace();

        }

    }


    public static Connection getConnection() throws Exception {

        if (conn == null) {

            conn = DriverManager.getConnection(url, username, password);

            return conn;

        }

        return conn;

    }


}

